<template>
  <div>
    <el-dialog title="添加英语作文" :visible.sync="dialogVisible">
      <el-form ref="form" :model="form" size="mini">
        <el-form-item label="行数" :label-width="formLabelWidth">
          <el-input-number :min="1" :max="20" v-model="form.lineCount" />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { uuid as createUUID, createHtmlSpace } from '@/assets/js/utils';
import { QUESTION_GROUP_TYPE_MAP, QUESTION_SIZE_MAP } from '@/assets/js/constant';
import CommonMixin from './common-mixin';

export default {
  mixins: [CommonMixin],
  computed: {
    submitData() {
      const uuid = createUUID();
      const groupType = QUESTION_GROUP_TYPE_MAP.EN_ARTICLE;
      const { title, idRange, lineCount } = this.form;
      const [startId, endId] = idRange;
      const { titleHeight } = QUESTION_SIZE_MAP;
      const { itemHeight, paddingBottomHeight } = QUESTION_SIZE_MAP.en_article;
      const height = titleHeight + lineCount * itemHeight + paddingBottomHeight;
      const totalHeight = height;
      const contents = [...new Array(lineCount)]
        .map((item, index) => {
          if (index === 0) {
            return `<p>${createHtmlSpace(4)}${startId}.${createHtmlSpace(3 - startId.toString().length)}<u>${createHtmlSpace(103)}</u></p>`;
          }
          return `<p>${createHtmlSpace(4)}<u>${createHtmlSpace(107)}</u></p>`;
        }).join('');
      const noSplitHeight = itemHeight;

      return {
        title,
        uuid,
        groupType,
        startId,
        endId,
        titleHeight,
        partIndex: 0,
        height,
        totalHeight,
        noSplitHeight,

        lineCount,
        contents,
      };
    },
  },
  methods: {
    resetFormData() {
      const beginId = this.getBeginId();
      return {
        title: '英语作文题',
        idRange: [beginId, beginId],
        lineCount: 10,
      };
    },
  },
};
</script>
